﻿<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../helpproject.xsl" ?>
<topic template="Default" lasteditedby="Geert" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../helpproject.xsd">
  <title translate="true">Using services</title>
  <body>
    <header>
      <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Using services</text></para>
    </header>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Services are very important in MVVM. They define a way to interact with the user without using fixed controls such as </text><text styleclass="Normal" style="font-style:italic;" translate="true">MessageBox</text><text styleclass="Normal" translate="true"> or </text><text styleclass="Normal" style="font-style:italic;" translate="true">SaveFileDialog</text><text styleclass="Normal" translate="true">. The interfaces defined in Catel only define generic functionality of what to expect from a specific service. Then, the actual implementation determines what interface implementation will be returned when a service uses the following call:</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">var</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">messageService</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">=</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">GetService&lt;IMessageService&gt;();</text></para>
    <para styleclass="Notes"><text styleclass="Notes" translate="true">Note that GetService&lt;&gt;() is only available on the ViewModelBase class. In all other cases, ServiceLocator.Instance.ResolveType&lt;&gt;() must be used</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">This call inside a </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_MVVM_ViewModelBase" styleclass="Normal" translate="true">ViewModelBase</link><text styleclass="Normal" translate="true"> implementation returns the actual implemented class that is registered as the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_MVVM_Services_IMessageService" styleclass="Normal" translate="true">IMessageService</link><text styleclass="Normal" translate="true"> implementation. For example, in Windows applications, the underlying implementation would use the </text><text styleclass="Normal" style="font-style:italic;" translate="true">MessageBox</text><text styleclass="Normal" translate="true"> class. But, during unit tests, you don&apos;t want to be bothered by a </text><text styleclass="Normal" style="font-style:italic;" translate="true">MessageBox</text><text styleclass="Normal" translate="true"> since there is no one that confirms it. Therefore, you can mock the </text><text styleclass="Normal" style="font-style:italic;" translate="true">IMessageService</text><text styleclass="Normal" translate="true"> interface during unit testing.</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The services below are available in Catel:</text></para>
    <para styleclass="Normal"><table styleclass="Default" rowcount="14" colcount="2">
      <tr style="vertical-align:top">
        <td style="width:164px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" style="font-weight:bold;" translate="true">Name</text></para>
        </td>
        <td style="width:1053px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" style="font-weight:bold;" translate="true">Description</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:164px;">
          <para styleclass="Normal (list)"><link displaytype="text" defaultstyle="true" type="topiclink" href="MVVM_Services_AccelerometerService" styleclass="Normal (list)" translate="true">IAccelerometerService</link></para>
        </td>
        <td style="width:1053px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Allows a developer to access the accelerometer of a Windows Phone 7 Mango device.</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:164px;">
          <para styleclass="Normal (list)"><link displaytype="text" defaultstyle="true" type="topiclink" href="MVVM_Services_CameraService" styleclass="Normal (list)" translate="true">ICameraService</link></para>
        </td>
        <td style="width:1053px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Allows a developer to use the </text><text styleclass="Normal (list)" style="font-style:italic;" translate="true">PhotoCamera</text><text styleclass="Normal (list)" translate="true"> class in an MVVM manner.</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:164px;">
          <para styleclass="Normal (list)"><link displaytype="text" defaultstyle="true" type="topiclink" href="MVVM_Services_CompassService" styleclass="Normal (list)" translate="true">ICompassService</link></para>
        </td>
        <td style="width:1053px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Allows a developer to access the compass of a Windows Phone 7 Mango device.</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:164px;">
          <para styleclass="Normal (list)"><link displaytype="text" defaultstyle="true" type="topiclink" href="MVVM_Services_GyroscopeService" styleclass="Normal (list)" translate="true">IGyroscopeService</link></para>
        </td>
        <td style="width:1053px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Allows a developer to access the gyroscope of a Windows Phone 7 Mango device.</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:164px;">
          <para styleclass="Normal (list)"><link displaytype="text" defaultstyle="true" type="topiclink" href="MVVM_Services_LocationService" styleclass="Normal (list)" translate="true">ILocationService</link></para>
        </td>
        <td style="width:1053px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Allows a developer to use GPS devices inside a view model.</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:164px;">
          <para styleclass="Normal (list)"><link displaytype="text" defaultstyle="true" type="topiclink" href="MVVM_Services_MessageService" styleclass="Normal (list)" translate="true">IMessageService</link></para>
        </td>
        <td style="width:1053px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Allows a developer to show message boxes from a view model.</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:164px;">
          <para styleclass="Normal (list)"><link displaytype="text" defaultstyle="true" type="topiclink" href="MVVM_Services_NavigationService" styleclass="Normal (list)" translate="true">INavigationService</link></para>
        </td>
        <td style="width:1053px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Allows a developer to navigate to other pages inside an application using view models only.</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:164px;">
          <para styleclass="Normal (list)"><link displaytype="text" defaultstyle="true" type="topiclink" href="MVVM_Services_OpenFileService" styleclass="Normal (list)" translate="true">IOpenFileService</link></para>
        </td>
        <td style="width:1053px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Allows a developer to let the user choose a file from inside a view model.</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:164px;">
          <para styleclass="Normal (list)"><link displaytype="text" defaultstyle="true" type="topiclink" href="MVVM_Services_PleaseWaitService" styleclass="Normal (list)" translate="true">IPleaseWaitService</link></para>
        </td>
        <td style="width:1053px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Allows a developer to show a please wait message (a.k.a. busy indicator) from a view model.</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:164px;">
          <para styleclass="Normal (list)"><link displaytype="text" defaultstyle="true" type="topiclink" href="MVVM_Services_ProcessService" styleclass="Normal (list)" translate="true">IProcessService</link></para>
        </td>
        <td style="width:1053px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Allows a developer to run processes from inside a view model.</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:164px;">
          <para styleclass="Normal (list)"><link displaytype="text" defaultstyle="true" type="topiclink" href="MVVM_Services_SaveFileService" styleclass="Normal (list)" translate="true">ISaveFileService</link></para>
        </td>
        <td style="width:1053px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Allows a developer to let the user choose a file from inside a view model.</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:164px;">
          <para styleclass="Normal (list)"><link displaytype="text" defaultstyle="true" type="topiclink" href="MVVM_Services_UIVisualizerService" styleclass="Normal (list)" translate="true">IUIVisualizerService</link></para>
        </td>
        <td style="width:1053px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Allows a developer to show (modal) windows or dialogs without actually referencing a specific view.</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:164px;">
          <para styleclass="Normal (list)"><link displaytype="text" defaultstyle="true" type="topiclink" href="MVVM_Services_VibrateService" styleclass="Normal (list)" translate="true">IVibrateService</link></para>
        </td>
        <td style="width:1053px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Allows a developer to start and stop vibration of the device via a service.</text></para>
        </td>
      </tr>
    </table></para>
  </body>
</topic>
